const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
module.exports={
    entry:"./src/index.js",
    output:{
        filename:"index.js",
        path:path.resolve(__dirname,'dist')
    },
    module:{
        rules:[
            {
                test:/\.js$/,
                use:"babel-loader",
                exclude:"/node_modules/"
            },
            {
                test:/\.css$/,
                use:[
                    "style-loader",
                    "css-loader",
                    "postcss-loader"
                ]
            },
            {
                test:/\.less$/,
                use:[
                    "style-loader",
                    "css-loader",
                    "postcss-loader",
                    "less-loader"
                ]
            },
            {
                test:/\.jpg$/,
                use:[
                    {
                        loader:'url-loader',
                        options:{
                            publicPath:"../img",//发布目录
                            outputPath:"img",//输出目录
                            limit:3000
                        }
                    }
                ]
            },
            {
                test:/\.(TTF|eot|woff|woff2|svg)$/i,
                use:[
                    {
                        loader:'file-loader',
                        options:{
                            publicPath:"../font",//发布目录
                            outputPath:"font"//输出目录
                        }
                    }
                ]
            },
            {
                test:/\.html$/,
                use:[
                    {
                        loader:'html-loader',
                        options:{
                            attributes:true
                        }
                    }
                ]
            }
        ]
    },
    plugins:[
        new HtmlWebpackPlugin({
            filename:`${__dirname}/dist/src/index.html`,
            template:"./index.html",
            inject:true //是否要自动插入打包生成的js文件
        }),
        new CleanWebpackPlugin()
        //压缩文件
        //性能优化 缓存
        //tree shaking
        //.....
    ]
}